package com.hrhx.springboot.fel;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.FelContext;

public class FelCore {
	
	private static FelEngine fel = new FelEngineImpl(); 
	private static FelContext ctx = fel.getContext();
	
	public static Double[][] getResult(String expression, Double[] data){
		Double resultData[][] = new Double[data.length][2];
        for(int i=0;i<data.length;i++){
        	ctx.set("x", data[i]);
        	Object evalDouble = fel.eval(expression,ctx);    
        	resultData[i][0]=data[i];
        	resultData[i][1]=Double.parseDouble(evalDouble.toString());
		}
        return resultData;
	}
}
